<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Global Mall</title>
    <link rel="icon" href="assets/image/logo/favicon.png" type="image/png" sizes="32x32">
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="assets/css/owl.carousel.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/owl.theme.default.min.css">
    <link rel="stylesheet" type="text/css" href="assets/fonts/css2.css">
    <link rel="stylesheet" type="text/css" href="assets/css/jquery.fancybox.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/all.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <link rel="stylesheet" type="text/css" href="assets/css/responsive.css">
</head>

<body>
    <div class="preloader"></div>
    <button id="myBtn" title="Go to top"></button>
    <?php
    // 引入数据库连接
    include 'conn.php';
    include 'header.php';
    if (!isset($_SESSION['user_id'])) {
        echo "<script>alert('请先登录！');window.location.href='login.php';</script>";
        exit;
    }
    ?>
    <!-- login page -->
    <div class="mb-3 mt-3">
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <ul class="breadcums">
                        <li class="d-inline-block font-weight-bolder button-group2">
                            <a href="index.php" class="login_txt symbol2 pro_home"></a>
                        </li>
                        <li class="d-inline-block hr_ font-weight-bolder"><a href="#" class="login_txt">个 人 中 心</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <?php
    $user_id = $_SESSION['user_id'];
    $sql = "SELECT * FROM users WHERE id = $user_id";
    $result = mysqli_query($conn, $sql);
    $user = mysqli_fetch_assoc($result);
    ?>

    <div class="container mb-5">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <h3 class="text-center login_head mt-4 page-title">个人信息</h3>
                <div class="card shadow p-4 mt-4">
                    <form action="update_profile.php" method="POST">
                        <div class="row">
                            <!-- 左侧头像 -->
                            <div class="col-md-4 d-flex flex-column align-items-center justify-content-center border-right">
                                <img src="<?php echo $user['avatar']; ?>" alt="用户头像" class="rounded-circle border mb-3" style="width: 120px; height: 120px; object-fit: cover;">
                                <!-- 修改头像按钮 -->
                                <button type="button" class="btn btn-sm btn-secondary mb-2" data-toggle="modal" data-target="#avatarModal">修改头像</button>
                            </div>
                            <!-- 右侧信息编辑 -->
                            <div class="col-md-8">
                                <div class="form-group mb-3 d-flex">
                                    <label class="nowant col-4 text-right pr-2">用户名：</label>
                                    <input type="text" class="form-control emaill col-8" name="username" value="<?php echo htmlspecialchars($user['username']); ?>" required>
                                </div>
                                <div class="form-group mb-3 d-flex">
                                    <label class="nowant col-4 text-right pr-2">真实姓名：</label>
                                    <input type="text" class="form-control emaill col-8" name="name" value="<?php echo htmlspecialchars($user['name']); ?>">
                                </div>
                                <div class="form-group mb-3 d-flex">
                                    <label class="nowant col-4 text-right pr-2">联系电话：</label>
                                    <input type="text" class="form-control emaill col-8" name="phone" value="<?php echo htmlspecialchars($user['phone']); ?>">
                                </div>
                                <div class="form-group mb-3 d-flex">
                                    <label class="nowant col-4 text-right pr-2">收货地址：</label>
                                    <textarea class="form-control emaill col-8" name="address" rows="2"><?php echo htmlspecialchars($user['address']); ?></textarea>
                                </div>
                                <div class="d-flex justify-content-between align-items-center pt-2">
                                    <!-- 修改密码按钮 -->
                                    <a href="#" class="font-weight-bolder" data-toggle="modal" data-target="#passwordModal">修改密码</a>
                                    <!-- 保存按钮 -->
                                    <button type="submit" class="btn btn-success btn-sm">保存修改</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- 修改头像模态框 -->
    <div class="modal fade" id="avatarModal" tabindex="-1" role="dialog" aria-labelledby="avatarModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <form action="update_avatar.php" method="POST" enctype="multipart/form-data" class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="avatarModalLabel">修改头像</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="关闭">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <input type="file" name="avatar" accept="image/*" class="form-control-file" required>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success btn-sm">上传</button>
                    <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">取消</button>
                </div>
            </form>
        </div>
    </div>
    <!-- 修改密码模态框 -->
    <div class="modal fade" id="passwordModal" tabindex="-1" role="dialog" aria-labelledby="passwordModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <form action="change_password_process.php" method="POST" class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="passwordModalLabel">修改密码</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="关闭">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="password" class="nowant">当前密码</label>
                        <input type="password" class="form-control emaill" id="password" name="current_password" placeholder="请输入密码" required>
                    </div>
                    <div class="form-group">
                        <label for="password" class="nowant">新密码</label>
                        <input type="password" class="form-control emaill" id="password" name="new_password" required>
                    </div>
                    <div class="form-group">
                        <label for="password" class="nowant">确认新密码</label>
                        <input type="password" class="form-control emaill" id="password" name="confirm_password" required>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success btn-sm">保存修改</button>
                    <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">取消</button>
                </div>
            </form>
        </div>
    </div>
    <?php
    include 'footer.php';
    ?>
    </script>
    <script src="assets/js/jquery-3.4.1.min.js"></script>
    <script src="assets/js/owl.carousel.js"></script>
    <script src="assets/js/popper.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/jquery.fancybox.min.js"></script>
    <script src="assets/js/custom.js"></script>
    <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
</body>

</html>